package pap;

import java.util.ArrayList;
import java.util.List;

public class TimesRegister {

	int STEP_NUMBER = 2;
	Long lastTime = null;
	List<Long> times;

	public TimesRegister() {
		times = new ArrayList<Long>();
	}

	public void recordStep() {
		if (lastTime != null) {
			times.add(System.nanoTime() - lastTime);
		}
		lastTime = System.nanoTime();

		if (times.size() == STEP_NUMBER) {
			computeAvg();
		}
	}

	private void computeAvg() {
		double timeSum = 0, avg;
		for (double time : times) {
			timeSum += time;
		}

		avg = timeSum / times.size();

		//System.out.println("La media dei tempi e' "+avg/(1000*1000*1000) +" secondi");
	}

}
